<?php 
if (!isset($_SESSION['login']) or !isset($_SESSION['senha'])) {
    header('location:/index.html');
 }
if($_SESSION['permissao'] === '1'){
         header('location: index.php');
       } 
	$i = 0;
	foreach ($_POST as $key => $value) {
		if ($value) {
			$ferramentas[$i] = $key;
			$i++;
		}
	}
	if (!isset($ferramentas)) {
		header("location:index.php?page=requisicao/adicionarferramenta.php&alert=Ferramenta!");
	}
	$vir = ",";
	$sql = "SELECT * from ferramenta WHERE nu_ferramenta IN(0";
	foreach ($ferramentas as $value) {
		$sql = $sql.$vir.$value;
	}
	$sql = $sql.")";
	$resultado = mysql_query($sql) or die("Erro no select da ferramenta".mysql_error());
?>
<script type="text/javascript">
function paint (id) {
        
        for (var i = 0; i < id; i++) {
            if (i % 2 == 0) {
                document.getElementById(i).style.backgroundColor='#E6F9F7';
            }else{
                document.getElementById(i).style.backgroundColor='#BED6F4';
            }
        }
    }
</script>
	<fieldset class="field" id="formulario">
		<legend>Cadastrar Requisição</legend>
		<form action="index.php?page=requisicao/cnovarequisicao.php" method="post">
 		<table class="tabela">
 							<tr>
 								<th colspan="6">Ferramenta Selecionada</th>
 							</tr>
 							<tr>
								<th>Nº Ferramenta</th>
								<th>Desc. Feramenta</th>
								<th>Marca</th>
								<th>Categoria</th>
								<th>Situação</th>
								<th>Data de Compra</th>
							</tr>
			 <?php $i = 0;while($linha = mysql_fetch_array($resultado)):?>					
						<input type="hidden" value="<?php echo $linha['nu_ferramenta']?>" name="<?php echo $i; ?>">
							<tr bgcolor="white">
								<td><?php echo $linha['nu_ferramenta']?></td>
								<td><?php echo $linha['descricao']?></td>
								<td><?php echo $linha['no_fabricante']?></td>
								<td><?php
								$sqlfun = "SELECT * FROM categoria_ferramenta";
								$resultFun = mysql_query($sqlfun);
								$arRefun = mysql_fetch_assoc($resultFun);
								do{
								if($arRefun['idcategoria'] == $linha['idcategoria']){
									   echo $arRefun['nome_categoria'];
									}
								}while($arRefun = mysql_fetch_assoc($resultFun))?></td>
								<td><?php
								$sqlfun = "SELECT * FROM situacao";
								$resultFun = mysql_query($sqlfun);
								$arRefun = mysql_fetch_assoc($resultFun);
								do{
								if($arRefun['idsituacao'] == $linha['idsituacao']){
									   echo $arRefun['descricao'];
									}
								}while($arRefun = mysql_fetch_assoc($resultFun))
								?></td>
								<td><?php echo $linha['dt_aquisicao']?></td>
							</tr>
								
							<?php $i++; endwhile;?>
		</table> <br/>		
		<label>Senha Atendente: </label><input type="password" name="senhaa"/><br/>
		<label>Matrícula Usuário: </label><input type="text" name="matricula"/><br/>
		<label>Senha Usuário: </label><input type="password" name="senhau"/><br/><br/><br/>
		<input class="alinha" id type="submit" value="Salvar">
 </form>
